



log(isExist("军务"))



/**
 * 
 * @param {输出日志} str 
 */
function logRecord(str) {
    toast(str)
    // log(str)
}

/**
OCR识图并点击（paddle）
*/
function clickCharEx_paddle(content, isDimFind, index, isClick, offsetX, offsetY, milliSecond) {
    if (!milliSecond) { milliSecond = 1000 };
    if (!index) { index = 0 };
    if (!offsetX) { offsetX = 0 };
    if (!offsetY) { offsetY = 0 };
    let result = false;
    let img = captureScreen();
    if (img) {
        let start = new Date();
        let res = paddle.ocr(img);
        logRecord('OCR识别耗时：' + (new Date() - start) + 'ms');
        if (res && res.length > 0) {
            for (let i = 0; i < res.length; i++) {
                let ocrResult = res[i];
                // logRecord(ocrResult);

                if (isDimFind && ocrResult.words.indexOf(content) != -1) {
                    logRecord("模糊找到");
                    logRecord(ocrResult.words)
                    result = true;
                } else if (content === ocrResult.words) {
                    logRecord("精确找到");
                    logRecord(ocrResult.words)
                    result = true;
                } else {

                }

                if (result) {
                    if (isClick) {
                        logRecord("点击")
                        click(ocrResult.bounds.left + parseInt((ocrResult.bounds.right - ocrResult.bounds.left) / 2) + offsetX, ocrResult.bounds.top + parseInt((ocrResult.bounds.bottom - ocrResult.bounds.top) / 2) + offsetY);
                        logRecord(ocrResult.bounds.left + parseInt((ocrResult.bounds.right - ocrResult.bounds.left) / 2) + offsetX +","+ ocrResult.bounds.top + parseInt((ocrResult.bounds.bottom - ocrResult.bounds.top) / 2) + offsetY)
                    }

                    break;
                }
            }
        }

        img.recycle();  // 回收图片
    } else {
        logRecord("截图失败");
    }

    if (result) {
        sleep(milliSecond);
    };
    return result;
};


function isExist(str) {
    let img = captureScreen();
    if (img) {
        let start = new Date()
        let result = paddle.ocr(img);
        log('OCR识别耗时：' + (new Date() - start) + 'ms')

        if (result && result.length > 0) {
            for (let i = 0; i < result.length; i++) {
                let ocrResult = result[i]
                logRecord(ocrResult.words)
                if (ocrResult.words == str) {
                    return true
                }
            }
        }

        // 回收图片
        img.recycle();
    } else {
        log("截图失败");
    }
    return false
}